package main;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

import control.ControlCommand;
import control.DrawButton;
import control.Panel;
import control.TabControl;
import control.TextControl;

public class SoundOnCanvas extends GameCanvas {
	protected final TabControl tabs;
	protected final MainMidlet game;
	//protected Image background;
	int state = -1;

	protected SoundOnCanvas(MainMidlet midlet) {
		super(true);
		this.game = midlet;
		setFullScreenMode(true);
		
		Panel panel;
		panel = new Panel(20, 20, 200, 360, 3);
		panel.setControl(0, new TextControl("Sound On?", 30, 50));
		panel.setControl(1,  new DrawButton(-1, 20, 340, 60, 40, "YES"));
		panel.get(1).setCommand(new ControlCommand() {
			public void Do() {
				tabs.setTab(1);
				state = 1;
			}
		});
		panel.setControl(2,  new DrawButton(-1, 160, 340, 60, 40, "NO"));
		panel.get(2).setCommand(new ControlCommand() {
			public void Do() {
				tabs.setTab(1);
				state = 0;
			}
		});
		
		tabs = new TabControl(2);
		tabs.setControl(0, panel);
		tabs.setControl(1, new TextControl("Loading...",5,5));
	}
	

	protected void pointerPressed(int x, int y) {
		tabs.pointerPressed(x, y);
		repaint();
	}

	protected void pointerReleased(int x, int y) {
		tabs.pointerReleased(x, y);
		repaint();
	}

	protected void pointerDragged(int x, int y) {
		tabs.pointerPressed(x, y);
		repaint();
	}

	public void paint(Graphics g) {
	//	g.drawImage(background, 0, 0, 0);
		g.setColor(0x886600);
		g.fillRect(0, 0, 240, 400);
		tabs.paint(g);
		if(state!=-1){
			Thread t = new Thread(new Runnable() {
			
			public void run() {
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				game.starGame(state==1);
			}
			});
			t.start();
		}

	}
}